package com.vitabuybuy.tv.ui.mine.order.adapter

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.library.common.widget.RecycleViewDivider
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ItemOrderDetailsBinding
import com.vitabuybuy.tv.dto.OrderDetailDto
import com.library.common.base.BindRecycAdapter

class OrderDetailAdapter : BindRecycAdapter<ItemOrderDetailsBinding, OrderDetailDto>() {
    private lateinit var goodItemAdapter: OrderGoodItemAdapter

    override fun onBindViewHolder(
        mBinding: ItemOrderDetailsBinding,
        itemData: OrderDetailDto,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        mBinding.itemData = itemData

        goodItemAdapter = OrderGoodItemAdapter(itemData.status)
        mBinding.rcvOrder.apply {
            adapter = goodItemAdapter
            layoutManager = LinearLayoutManager(mContext)
            addItemDecoration(RecycleViewDivider(mContext, 1))
            setHasFixedSize(true)
            isNestedScrollingEnabled = false
        }
        goodItemAdapter.setNewData(itemData.itemList)
        goodItemAdapter.onClickAfterSale = {
            onClickAfterSale.invoke(position, it)
        }
        mBinding.btnCallShop.setOnClickListener {
            onClickCallShopListener.invoke(position)
        }
    }

    lateinit var onClickAfterSale: (parentPos: Int, childPos: Int) -> Unit
    lateinit var onClickCallShopListener: (parentPos: Int) -> Unit


    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_order_details
    }

}
